extends Line2D
@export var enable:bool=true
@export var target_pos:Node2D
@export var max_point_count:int = 10
@export var sensitivity:int = 10
@export var delay_fps:int = 0

var _prev_pos:Vector2
var _cnt_delay_fps:int=0

func _ready() -> void:
	top_level = true
	clear_points()
	if target_pos:
		_prev_pos = target_pos.global_position
@warning_ignore("unused_parameter")
func _physics_process(delta: float) -> void:
	if delay_fps>0:
		_cnt_delay_fps+=1
		if _cnt_delay_fps>delay_fps:
			_cnt_delay_fps=0
		else:return
	if target_pos and enable:
		if (target_pos.global_position-_prev_pos).length() > sensitivity:
			if get_point_count()<max_point_count:
				add_point(target_pos.global_position)
			else:
				add_point(target_pos.global_position)
				remove_point(0)
		else:
			if get_point_count()>0:remove_point(0)
		_prev_pos = target_pos.global_position
	else:
		if get_point_count()>0:remove_point(0)
